/**
 * @ author: 汪孟苹
 */
define(["jquery","bbcare","oms_config/root","fu/app/comm/comm",
    "scprit/followup/app/datatable/datatable.ui.js",
    "scprit/department/vm/allPatients.servers.js"],
    function ($,$bb,$root,$comm,$datatableUi,$allPatientsServers) {
    var allPatients = {};

    var ajaxQueueCallBack = function(rows){
        $comm.selectQueue({
            "id": "queue",
            "list": rows
        });
    }
    var onNumBlur = function(){
        var reg = /^[0-9]*$/;
        var val = $(this).val();
        if(!reg.test(val)){
            $bb.toastShow("年龄请输入数字类型",1500);
            $(this).val("").focus();
        }
    }
    var onPhoneNumBlur = function(){
        var reg = /^$|^1\d{10}$/;
        if(!reg.test($(this).val())){
            $bb.toastShow("手机格式不正确",1500);
            $(this).val("").focus();
        }
    }
    allPatients.init = function(){
        var params = $bb.getPageParams();
        if(params && params.followQueueId){
            $("#queueBox").css({"display":"none"});
        }
        $("#phoneNum").blur(onPhoneNumBlur);
        $("#ageFrom-year,#ageFrom-month,#ageTo-year,#ageTo-month").blur(onNumBlur);
        $allPatientsServers.ajaxQueue(ajaxQueueCallBack);
        $datatableUi.init({
            "id": "allPatients",
            "options": $allPatientsServers.getOptions()
        });  
        var config = $root.init();
        if(!config.dom.allPatientsLook){
            $datatableUi.table.api().column('.operate').visible(false);
        }
        if(!config.dom.allPatientsBirthdate){
            $datatableUi.table.api().columns('.birthday').visible(false);
        }
        if(!config.dom.allPatientsHisNo){
            $datatableUi.table.api().column('.hisNo').visible(false);
        }
        if(!config.dom.allPatientsWeight){
            $datatableUi.table.api().column('.weight').visible(false);
        }
    }

    return allPatients;
});